import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { normalizePath } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import glbModelsPlugin from './src/renderer/src/utils/vite-plugin-glb-models'
import { viteStaticCopy } from 'vite-plugin-static-copy'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@': resolve('src/renderer/src')
      }
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      glbModelsPlugin(),
      viteStaticCopy({
        targets: [
          {
            //__dirname 是 Node.js 中的一个全局变量，表示当前执行脚本所在的目录的绝对路径
            //  使用 resolve 将相对路径转换为绝对路径
            // 然后使用 normalizePath 确保路径使用正斜杠，兼容所有操作系统
            src: normalizePath(resolve(__dirname, 'node_modules/earthsdk3-assets')),
            dest: './js'
          }
        ]
      })
    ],
    define: {
      CESIUM_BASE_URL: JSON.stringify('cesiumStatic')
    },
    base: './'
  }
})
